package com.ruoyi.bigscreen.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.ruoyi.bigscreen.domain.TmAssets;
import com.ruoyi.bigscreen.domain.TmLoophole;
import com.ruoyi.bigscreen.domain.TmToolkit;
import com.ruoyi.bigscreen.service.TmBigScreenService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author Ding
 * @date 2021/1/22
 */
@RestController
@RequestMapping("/bigScreen")
public class bigScreenController extends BaseController {
    @Autowired
    private TmBigScreenService tmBigScreenService;

    @PostMapping("/tmOrganization")
    public String parseTmOrganizationJson(){
        return tmBigScreenService.TmOrganizationToJson();
    }

    @PostMapping("/tmOrganization1")
    public String parseTmOrganizationJson1(){
        return tmBigScreenService.TmOrganizationToJson1();
    }

    @PostMapping("/bigScreenGetOrganizations/{orgCamp}")
    public String getOrganizations(@PathVariable("orgCamp") String orgCamp){
        String json = JSON.toJSONString(tmBigScreenService.getOrganizationsByOrgCamp(orgCamp));
        return json;
    }

    @PostMapping("/bigScreenGetToolkit/{orgCamp}")
    public String getToolkits(@PathVariable("orgCamp") String orgCamp){

        return tmBigScreenService.getToolkitsByOrgCamp(orgCamp);
    }

    @PostMapping("/bigScreenGetLoopHoleByOrgCamp/{orgCamp}")
    public String getLoopHoleByOrgCamp(@PathVariable("orgCamp") String orgCamp){
        String json = JSON.toJSONString(tmBigScreenService.getLoopHoleByOrgCamp(orgCamp));
        return json;
    }

    @PostMapping("/bigScreenGetOrgPercent/{orgCamp}")
    public String getOrgPercentByOrgCamp(@PathVariable("orgCamp") String orgCamp){
        return tmBigScreenService.orgPercent(orgCamp);
    }

    @PostMapping("/bigScreenOverView/{orgCamp}")
    public String getOverViewByOrgCamp(@PathVariable("orgCamp") String orgCamp){
        return tmBigScreenService.getOverViewByOrgCamp(orgCamp);
    }

    @PostMapping("/bigScreenDeleteDatas")
    @ResponseBody
    public AjaxResult deleteDatas(@RequestBody String jsonString){
        try {
            tmBigScreenService.deleteDatas(jsonString);
        }catch (Exception e){
            return AjaxResult.error();
        }
        return AjaxResult.success();
    }

    @PostMapping("/bigScreenAddDatas")
    @ResponseBody
    public AjaxResult addDatas(@RequestBody String jsonString){
        try {
            tmBigScreenService.addDatas(jsonString);
        }catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.error();
        }
        return  AjaxResult.success();
    }

    @PostMapping("/bigScreenChinaMap")
    public String getChinaMapData(){

        return  tmBigScreenService.getChinaMapData();
    }


    @PostMapping("/getOne")
//    public String getOne(@PathVariable("orgCamp") String orgCamp){
    public String getOne(){
        Map<String,List> lists = new HashMap();
        List<String> one = new ArrayList<>();

        List<TmToolkit> onea = tmBigScreenService.selectTmToolkit();
        List<Integer> one1 = new ArrayList<>();
        List<Integer> one2 = new ArrayList<>();
        for (TmToolkit t:onea) {
            one.add(t.getLoadName());
            one1.add(Integer.parseInt(t.getLoadType()));
            one2.add(Integer.parseInt(t.getLoadStatus()));
        }
        lists.put("category",one);
        lists.put("lineData",one1);
        lists.put("barData",one2);
        String json = JSON.toJSONString(lists);
        return json;
    }

    @PostMapping("/getTwo")
    public String getTwo(){
        Map<String,List> lists = new HashMap();
        List<String> one = new ArrayList<>();
        List<Map<String,Object>> one1 = new ArrayList<>();
        List<TmLoophole> onea = tmBigScreenService.selectTmLoophole();
        for (TmLoophole t:onea) {
            one.add(t.getLoopholeName());
            Map<String,Object> aa = new HashMap<>();
            aa.put("value",t.getLoopholeNum());
            aa.put("name",t.getLoopholeName());
            one1.add(aa);
        }
        lists.put("xData",one);
        lists.put("seriesData",one1);
        String json = JSON.toJSONString(lists);
        return json;
    }

    @PostMapping("/getTwo1")
    public String getTwo1(){
        List<Object> one = new ArrayList<>();
        List<TmLoophole> onea = tmBigScreenService.selectTmLoophole();
        for (TmLoophole t:onea) {
            Map<String,Object> aa1 = new HashMap<>();
            List<Object> b1 = new ArrayList<>();
            Map<String,Object> aaa1 = new HashMap<>();
            b1.add(Integer.parseInt(t.getLoopholeNum()));
            aaa1.put("number",b1);
            aa1.put("number",aaa1);
            aa1.put("text",t.getLoopholeName());
            one.add(aa1);
        }
        String json = JSON.toJSONString(one);
        return json;
    }

    @PostMapping("/getTwo2")
    public String getTwo2(){
        Map<String,Object> aa = new HashMap<>();
        List<Object> a = new ArrayList<>();
        List<TmAssets> onea = tmBigScreenService.selectTmAssets();
        for (TmAssets t:onea) {
            List<Object> b = new ArrayList<>();
            b.add(t.getAssetsName());
            b.add(t.getAssetsStatus());
            b.add("<span  class='colorRed'>"+t.getAssetsCamp()+"</span>");
            a.add(b);
        }
        List<Object> ab = new ArrayList<>();
        ab.add("资源名称");
        ab.add("资源状态");
        ab.add("资源阵营");
        aa.put("header",ab);
        aa.put("data",a);
        aa.put("rowNum",7);
        aa.put("headerHeight",35);
        aa.put("headerBGC","#0f1325");
        aa.put("oddRowBGC","#0f1325");
        aa.put("evenRowBGC","#171c33");
        aa.put("index",true);
        List<Object> abc = new ArrayList<>();
        abc.add(50);
        List<Object> abcd = new ArrayList<>();
        abcd.add("center");
        aa.put("columnWidth",abc);
        aa.put("align",abcd);
        String json = JSON.toJSONString(aa);
        return json;
    }

}
